﻿package com.view;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import com.base.standardization;
import com.data.Data;
import com.db.service.GroupServer;
import com.db.sevent.GroupEvent;
import com.db.sevent.WorkEvent;

import util.GUIUtil;

public class P1 extends JPanel implements standardization{
	public JComboBox<String> com01;
	public JButton bt01,bt02,bt02_1,bt03,bt04,bt05,bt06;
	public JList<String> list01;
	private JScrollPane scrollPane01;
	public String t = "21";
	
	public static P1 instance = new P1(); 
	
	private P1() {
		init();
		event();
		System.out.println("加载P1成功");
	}
	public void init() {
		//面板基本结构 修改
		setLayout(null);
		int WIDTH = Data.config.PanelW1;
		int HEIGHT = Data.config.HEIGHT;
		setBounds(0, 0,  WIDTH, HEIGHT);
		setBackground(new Color(255, 200,  255));
		
		//控件
		com01 = new JComboBox<String>();
		bt01 = new JButton("增");
		bt02 = new JButton("删");
		bt03 = new JButton("创建作业");
		bt04 = new JButton("发布作业");
		bt05 = new JButton("删除作业");
		bt02_1= new JButton("改");
		bt06 = new JButton("修改作业");
		list01 =  new JList<String>();
		scrollPane01 = new JScrollPane();
		
		initLayout();
		initOther();
		add(bt01);
		add(bt02);
		add(bt02_1);
		add(bt03);
//		add(bt04);
		add(bt05);
		add(com01);
		add(scrollPane01);
		add(bt06);
	}

	@Override
	public void initLayout() {
		com01.setBounds(10, 10, 167, 21);
		bt01.setBounds(7, 38, 53, 29);
		bt02.setBounds(129, 38, 53, 29);
		bt02_1.setBounds(70, 38, 53, 29);
		scrollPane01.setBounds(10, 72, 172, 342);
		bt03.setBounds(18, 424, 136, 23);
		bt04.setBounds(19, 453, 136, 23);
		bt05.setBounds(18, 486, 136, 20);
		bt06.setBounds(20, 457, 134, 20);
	}

	@Override
	public void initOther() {
		// TODO Auto-generated method stub
		scrollPane01.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		scrollPane01.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
		scrollPane01.setViewportView(list01);
		
	}

	@Override
	public void initEvent() {
		//初始组
//		System.out.println("P1执行");
		
	}

	@Override
	public void event() {
		bt01.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new GroupEvent().newGeoup();
			}
		});
		bt02.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new GroupEvent().deleteWorkGroup();
			}
		});
		bt02_1.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				new GroupEvent().updateGroup();
			}
		});
		bt03.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				//代码
				new WorkEvent().insertWork();
			}
		});
		bt04.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				//代码
				new WorkEvent().issue();
			}
		});
		bt05.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				//代码
				new WorkEvent().deleteWork();
			}
		});
		bt06.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				new WorkEvent().updateWorl();
			}
		});
	   list01.addMouseListener(new MouseAdapter() {
		   @Override
			public void mousePressed(MouseEvent e) {
			   new WorkEvent().clickWorkList();
			}
	   });
	   com01.addActionListener(new ActionListener() {
		@Override
		public void actionPerformed(ActionEvent e) {
			new WorkEvent().getWorkList();
		}
	});
	}
	/*暴露到外面的方法区*/
	//********************************组件暴露出去的方法  SET GET***************************//
	public void setList01Data(String[] list) {
		//字符串列表转对应类型
		DefaultListModel m = new DefaultListModel();
		for (int i = 0; i < list.length; i++) {
			m.add(i,list[i]);
		}
		list01.setModel(m);
	}
	public int getListData() {
		return list01.getSelectedIndex();
	}
	public int getCom01Date() {
		return com01.getSelectedIndex();
	}
	public static void main(String[] args) {
		String[] list = {"1","5","3"};
		P1.instance.setList01Data(list );
		GUIUtil.showPanel(P1.instance);
	}
}
